function setPassword(account,vcode,password) {
    return hex_md5(password);
}

$(".toggle").on('click',function () {

    if($(".toggle").hasClass('glyphicon-eye-open')) {

        $(".toggle").removeClass('glyphicon-eye-open').addClass('glyphicon-eye-close');
        $("#password").attr('type','text');
    }else {
        $(".toggle").removeClass('glyphicon-eye-close').addClass('glyphicon-eye-open');
        $("#password").attr('type','password');
    }
})

function Alert(msg) {
    window.alert(msg);
}
$(".dl").on('click',function (){
    var name = $("#name").val();
    var password = $("#password").val();
    var vcodeVal = $('#check').val()
    var Pass = setPassword(name,vcodeVal,password);
    var data = {account:name,secPassword:Pass}
    data.vcodeVal = $('#check').val()
    if(!name){
        alert("用户名不能为空");
        return false;
    }
    if(!password){
        alert("密码不能为空");
        return false;
     }
     if(!vcodeVal){
        alert("验证码不能为空");
        return false;
     }
     $(this).css({disabled:true});
     $(this).text("登录中...");
    $.post({
        url:rootUrl+'/api/login',
        dataType:'text',
        data,
        success:function (resText) {
        	console.log(resText);
        	var result = eval("("+resText+")");
            switch (result['code']){
                case 'success':
                	$('body').addClass('page-is-changing');
                	setTimeout(function(){
                		location.href=rootUrl+'/main.html';
                	},1600)
                    break;
                default :
                    $(".dl").css({disabled:false});
                    $(".dl").text("登录");
                	Alert(result['msg']);
                	$(".checkimg").click();
                	$("#check").val("");
                	break;
            }
        }
    })
    return false;
})

//点击验证码刷新
$(".checkimg").on('click',function(){
	this.src = rootUrl + vcodeUri +'?t='+new Date();
})
//点击回车，映射登录
$(".login").bind("keydown",function(e){
        // 兼容FF和IE和Opera    
    var theEvent = e || window.event;    
    var code = theEvent.keyCode || theEvent.which || theEvent.charCode;    
    if (code == 13) {    
        //回车执行查询
            $(".dl").click();
        }    
});
